// 作者： 张元喆
// 邮箱：zzzzyzzzz@qq.com
import Vue from 'vue'
import Router from 'vue-router'
import login from '@/components/login'
// import  Main  from 'element-ui'
// import Main from '@/components/Main'
import Wel from '@/components/wel'
import Order from '@/components/order'
import Product from '@/components/product'
import Manager from '@/components/manager'
import Main from '@/components/main'
import Register from '@/components/register'
import UserCenter from '@/components/userCenter'
// import Cookies from 'js-cookie'







Vue.use(Router)

const router =  new Router({
  mode : 'history',
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name : 'login',
      component: login,
    },
    {
      path: '/register',
      name : 'register',
      component: Register,
    },
    {
      path: '/main',
      name: 'main',
      component: Main,
      // redirect: '/wel',
      children: [ //定义子组件
        {
          path: '/wel',
          name : 'wel',
          component: Wel,
        },
        {
          path: '/order',
          name : 'order',
          //  meta :
          component: Order
        },
        {
          path: '/product',
          name : 'product',
          component: Product,
        },
        {
          path: '/manager',
          name : 'manager',
          component: Manager,
          // beforeEnter: (to, from, next) => {
            
          //   if(Cookies.get('adminFlag')==1){
          //     next();
          //     // next('/manager');
          //   }
          //   else{
          //     this.$message({
          //       message: "请联系管理员",
          //       type: "error",
          //     });
          //   }
          // }
        },
        {
          path: '/userCenter',
          name : 'userCenter',
          component: UserCenter,
        }
         
        
        ]
    }
    
  ]
})

  
// router.beforeEach((to, from, next) => {
 
//   if (to.path == '/login') {
//         next();
//       } 
  
//       else {
//         if (sessionStorage.getItem("username")) {
//           next();
//         } else {
//         
//           next({
//             path: '/login'
//           })
//         }
//       }
//     })
export default router
